package com.zwr.sheller.customer.controller;

import com.zwr.sheller.core.common.BusinessException;
import com.zwr.sheller.core.common.JsonResult;
import com.zwr.sheller.core.common.WDMBusinessException;
import com.zwr.sheller.core.pojo.Order;
import com.zwr.sheller.core.pojo.OriginOrder;
import com.zwr.sheller.customer.Service.OrderService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpRequest;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.Map;

@RestController
@RequestMapping("/ordercustomer")
@Api("订单模块")
public class OrderController {

    @Autowired(required = false)
   private OrderService orderService;

    @Autowired
    private HttpServletRequest request;


    @PostMapping("/creatOrder")
    @ApiOperation(value = "提交订单")
    @ApiImplicitParams({
            /*@ApiImplicitParam(name = "AddressId",value = "地址Id",dataType = "Long"),
            @ApiImplicitParam(name = "skuIdWithNumber",value = "对应的商品Sku以及数量",dataType = "Map"),
            @ApiImplicitParam(name = "orderDeliveryMethod",value = "配送方式（1.商家配送，2.平台统一配送，3.上门自提）",dataType = "Long"),
            @ApiImplicitParam(name = "orderWithBill",value = "是否开具发票（1.开发票，2.不开发票",dataType = "Long"),
            @ApiImplicitParam(name = "orderBillType",value = "发票类型（1.普通发票，2.增值税专用发票）（开发票才需要该字段）",dataType = "Integer"),
            @ApiImplicitParam(name = "orderBillInvoice",value = "发票抬头（1.个人抬头，2.企业抬头）（开发票才需要该字段",dataType = "Long"),
            @ApiImplicitParam(name = "orderRemark",value = "给商家的备注",dataType = "String"),
            @ApiImplicitParam(name = "oranizationName",value = "工作单位名称（发票）",dataType = "String"),
            @ApiImplicitParam(name = "invoiceContent",value = "发票内容（1.商品类别 2.商品详情）（发票）",dataType = "Integer"),
            @ApiImplicitParam(name = "taxpayerIdentificationNumber",value = "纳税人识别号（发票）",dataType = "String"),
            @ApiImplicitParam(name = "shopId",value = "对应的商铺Id",dataType = "Long"),*/
    })
    public Map<String,Object> createOrder(@RequestBody Map<String ,Object> maps) throws WDMBusinessException, BusinessException {
        OriginOrder order = orderService.createOrder(maps);
        JsonResult jsonResult = new JsonResult();
        jsonResult.setCode("1");
        jsonResult.setMsg("订单生成成功");
        jsonResult.setField("Data",order);
        return jsonResult.getMap();
    }

    /**
     * 支付回调接口
     * @return
     */
    @GetMapping("/updateOrder")
    public Map<String,Object> updateOrder(){
        String orderNum = request.getParameter("order_num");
        OriginOrder order = new OriginOrder();
        order.setOrderNum(orderNum);
        order.setOrderStatus(2);
        orderService.updateOrderField(order);
        JsonResult jsonResult = new JsonResult();
        jsonResult.setCode("1");
        jsonResult.setMsg("购买成功");
        return jsonResult.getMap();

    }

}
